home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 October / Macworld (1998-10).dmg / Shareware World / Info / For Developers / MacZoop 1.8.4 / Required Classes / Z Headers / ZApplication.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-16  |  5.0 KB  |  201 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            MacZoop - "the framework for the rest of us"         
  5. *
  6. *
  7. *
  8. *            ZApplication.h            -- the application object
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21.  
  22. #pragma once
  23.  
  24. #ifndef __ZAPPLICATION__
  25. #define    __ZAPPLICATION__
  26.  
  27. #ifndef __ZCOMMANDER__
  28. #include    "ZCommander.h"
  29. #endif
  30.  
  31. class    ZEventHandler;
  32. class    ZWindow;
  33. class    ZUndoTask;
  34. class    ZPrinter;
  35. class    ZMenuBar;
  36.  
  37. // for easier adoption of navigation services, the fileTypes handle now incorporates a
  38. // header such that it mimics an 'open' resource.
  39.  
  40. #if PRAGMA_ALIGN_SUPPORTED
  41. #pragma options align=mac68k
  42. #endif
  43.  
  44. typedef struct
  45. {
  46.     OSType    appSignature;
  47.     short    reserved;
  48.     short    osTypeCount;
  49.     OSType    osType[1];
  50. }
  51. FTypeList, *FTypeListPtr, **FTypeListHdl;
  52.  
  53. #if PRAGMA_ALIGN_SUPPORTED
  54. #pragma options align=reset
  55. #endif
  56.  
  57. // app class info:
  58.  
  59. DEFINECLASSID( ZApplication, 'zapp' );
  60.  
  61. // app class definition:
  62.  
  63. class    ZApplication : public ZCommander
  64. {
  65.     friend class ZEventHandler;
  66.     
  67. protected:
  68.  
  69.     Boolean            done;                // normally FALSE, if set TRUE, will try to quit
  70.     short            phase;                // current phase
  71.     short            appResRefNum;        // refnum of application resource file
  72.     ZEventHandler*    zEH;                // event handler object
  73.     ZWindow*        mostRecent;            // most recently created window
  74.     Handle            shortageFund;        // to deal with tight memory, we can release this
  75.     FTypeListHdl    itsFileTypes;        // list of filetypes we can open
  76.     ZUndoTask*        curUndoTask;        // current undoable task
  77.     ZPrinter*        itsPrinter;            // printer object for handling print commands
  78.     Boolean            memIsShort;            // flag memory problem
  79.     Boolean            userHasSeenAlert;    // TRUE if user has been warned about the memory
  80.  
  81. public:    
  82.  
  83.     ZApplication();
  84.     virtual ~ZApplication();
  85.     
  86.     // initialisation and clean-up
  87.     
  88.     virtual void        InitMacZoop( const short numMasterBlocks = 8 );
  89.     virtual void        StartUp() {};
  90.     virtual void        ShutDown() {};
  91.     virtual void        ReadPrefs() {};
  92.     
  93.     // event processing
  94.     
  95.     virtual void        Run();
  96.     virtual Boolean        Quit();
  97.     virtual void        RequestQuit();
  98.     virtual Boolean        MemoryShortage( const Size bytesShort );
  99.     virtual void        Process1Event();
  100.     virtual void        Process1Event( EventRecord* anExternalEvent );
  101.     virtual void        HandleCommand( const long aCmd );
  102.     virtual void        HandleCommand( const short menuID, const short itemID );
  103.     virtual void        UpdateMenus();
  104.     virtual Boolean        GetCurrentEvent( EventRecord* anEvent );
  105.     virtual void        HandleAppleEvent(    AEEventClass aeClass, AEEventID aeID,
  106.                                             AppleEvent* aeEvt, AppleEvent* reply );
  107.                                             
  108.     virtual void        MouseNotInAnyWindow( const Point globalMouse );
  109.     virtual void        WaitApplicationForeground();
  110.     virtual void        ProcessHLEvent( const EventRecord& theEvent ) {};
  111.                                             
  112.     // status utilities
  113.     
  114.     virtual    short        GetClicks();
  115.     virtual    Boolean        InBackground();
  116.     virtual void        GetName( Str255 appName );
  117.  
  118.     // error processing
  119.     
  120.     virtual void        HandleError( OSErr theErr );
  121.     
  122.     // window construction
  123.     
  124.     virtual void        OpenNewWindow();
  125.     virtual ZWindow*    OpenNewWindowType( OSType aType = 0 );
  126.     virtual void        CloseAll( Boolean closeFloaters = FALSE );
  127.     virtual ZWindow*    GetFrontWindow();
  128.     virtual void        AboutBox();
  129.     virtual void        DoPreferences() {};
  130.     
  131.     // opening files
  132.     
  133.     virtual Boolean        PickFile( FSSpec* aFile, OSType* fType );
  134.     virtual void        OpenFile( const FSSpec& aFile, const OSType fType, Boolean isStationery = FALSE );
  135.     
  136.     // extending the file types
  137.     
  138.     virtual void        AddFileType( const OSType aType );
  139.     virtual Boolean        CanOpenFileType( const OSType aType );
  140.     
  141.     // undo task handling
  142.     
  143.     virtual void        SetTask( ZUndoTask* aTask );
  144.     virtual void        UpdateUndo();
  145.     inline ZUndoTask*    GetUndoTask() { return curUndoTask; };
  146.     
  147.     // printer handling
  148.     
  149.     virtual void        MakePrinter();
  150.     virtual void        DoPageSetup();
  151.     virtual void        DoPrint();
  152.     inline    ZPrinter*    GetPrinter() { return itsPrinter; };
  153.     
  154.     // other inline accessors
  155.     
  156.     inline    short            GetPhase()                        { return phase;};
  157.     inline    FTypeListHdl    GetFileTypeList()                 { return itsFileTypes; };
  158.     inline    Boolean            MemoryCrisis()                     { return memIsShort; };
  159.     inline    Boolean            UserHasSeenMemoryCrisisAlert()     { return userHasSeenAlert; };
  160.     inline    ZEventHandler*    GetEventHandler()                 { return zEH; };
  161.     inline    short            GetAppRefnum()                     { return appResRefNum; };
  162.     
  163. protected:
  164.  
  165.     void                InitMacApplication( const short numMasterBlocks );
  166.     virtual void        MakeEventHandler();
  167.     virtual void        MakeClipboard();
  168.     virtual Boolean        CheckCanRun();
  169.     virtual void        InitMenuBar();
  170.     virtual void        MakeNewWindow();
  171.     virtual ZWindow*    MakeNewWindowType( OSType aType = 0 ) { MakeNewWindow(); return mostRecent; };
  172.     virtual void        CheckLowMemory();
  173.     virtual void        RegisterClasses();
  174. };
  175.  
  176. // possible values of "phase"
  177.  
  178. enum
  179. {
  180.     kInitialising,
  181.     kRunning,
  182.     kQuitting
  183. };
  184.  
  185. enum
  186. {
  187.     kDefaultWindowType = 0
  188. };
  189.  
  190. #define        kUndoStrIndex                5
  191. #define        kRedoStrIndex                6
  192. #define        kCantUndoStrIndex            7        
  193.  
  194. #define        kCantRunAlertID                131
  195. #define        kFatalStartupErrAlertID        136
  196.  
  197. #define        kAEReopenApplication        'rapp'    // new MacOS 8 apple event
  198.  
  199.  
  200.  
  201. #endif